<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core\lang;
use classlib\core as C;
use classlib\core\controller;
class Cpayment extends controller {
	public function main() {
		$view   = C\view::inst('extjs');
		$userid = Cadmin::chkaccess($view);
		$dlang  = lang::inst('dd');
		$view->assign('status', $dlang->get('sh0005'));
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('live/finance/payment.ext.js');
	}
	
	public function dolist() {
		$view   = C\view::inst('json');
		Cadmin::chkaccess($view);
		list($start, $limit, $sort) = Cadmin::offset();
		$where  = array();
		$userid = input::post('userid');
		if(is_numeric($userid) && $userid > 0) {
			$where[] = array('userid', $userid, \classlib\orm::OP_EQ);
		}
		$status = input::post('status');
		if (is_numeric($status)) {
			$where['status'] = $status;
		}
		$sdate  = input::post('sdate');
		if ($sdate) {
			$where[] = array('stime', strtotime($sdate), \classlib\orm::OP_GT);
		}
		$edate  = input::post('edate');
		if ($edate) {
			$where[] = array('stime', strtotime($edate), \classlib\orm::OP_LT);
		}
		
		$orm   = C\model::load('pro.pl.payment');
		$total = $orm->get_total($where);
		$list  = array();
		if ($total) {
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			$orm  = C\model::load('pro.pl.userinfo');
			foreach ($list as &$item) {
				$user  = $orm->get_one($item['userid']);
				$item['stime']   = date('Y-m-d H:i:s', $item['stime']);
				$item['nickname']= $user['nickname'];
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}